<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<%@include file="/WEB-INF/taglibs/common/taglibs.jsp"%>
<head>
<title><spring:message code="admin.orderstatulist.title" /></title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" href="<c:url value="/css/styles.css"/>" />
<script src="<c:url value="/javascripts/common.js"/>"></script>
<script language="javascript">
// script added by Umme Essa. The form should be validated on all operations.
	 var functionName="";
	 function validateForm(){
		 if(functionName == 'add')
			 return (validate_required(document.getElementById("newOrderStatusName"),'Please enter order status name.'));
		 if(functionName == 'remove'){
			if(isAnyCheckBoxSelected("selecter"))return true;
			else {
				alert("Please select a record to remove");
				return false;
			}
		 }
		 
		 if(functionName == 'save'){
			 if(!checkEmptyValues()){
				 alert("Please fill name field for all the records");
				 return false;
			 }
			 return true;
		 }
		 return false;
	 }

	 function checkEmptyValues(){
		 var formObj=document.forms[0];
		 for (i=0; i<formObj.elements.length; i++){
		 if (formObj.elements[i].type=="text" && formObj.elements[i].id.indexOf("name")!= -1)
		 if (formObj.elements[i].value=="") //if empty field
			return false;
		 }
		 return true;
	 }
	 
	 function isAnyCheckBoxSelected(selecter){
		 var items = document.forms[0].selecter;
		 var length=getLength(items);
		 var item=null;
		 	for(i=0;i<length;i++)
		 	{	item=getItemAt(items,i);
		 		if(item.checked)
		 			return true;
		 	}
		 return false;
		 }

		
		 
	 </script>
</head>

<body><%@include file="../top_menu.jsp"%><table width="100%">
	<tr>
		<td><c:import url="/WEB-INF/jsp/menu/view_orders_menu.jsp" />
		</td>
	</tr>
	<tr>
		<td><%@include file="/WEB-INF/jsp/include/messages.jsp"%>
		<br />
		</td>
	</tr>
</table>
<table width=70%>

	<tr>
		<td class="pageHeading"><spring:message code="admin.orderstatulist.label.orderstatuslist" /> <br />
		</td>
	</tr>

</table>
<form:form commandName="orderStatusForm" method="post"
	onsubmit='return validateForm()'>
	<table width=70% class="formTable">

		<tr class="formHeader">
			<td><spring:message code="admin.orderstatulist.label.orderstatus" /></td>
		</tr>
		<tr>
			<td valign="top">

			<table border="0" cellpadding="4" cellspacing="1" width="100%">
				<thead>

					<tr>
						<th><spring:message code="admin.orderstatulist.label.name" /></th>
						<th><spring:message code="admin.orderstatulist.label.meaning" /></th>
						<th><spring:message code="admin.orderstatulist.label.active" /></th>
						<th><spring:message code="admin.orderstatulist.label.select" /> <a href="order_status_list.jsp#"
							onclick="return ch_select(true,'checked');"><spring:message code="admin.orderstatulist.label.all" /></a> / <a href="order_status_list.jsp#"
							onclick="return ch_select(false,'checked');"><spring:message code="admin.orderstatulist.label.none" /></a></th>
					</tr>
				</thead>
				<tbody>
					<c:if test="${empty orderStatusForm.orderStatusList}">
						<tr>
							<td colspan="12"><spring:message code="admin.orderstatulist.label.noorderstatuswerefound" /></td>
						</tr>
					</c:if>
					<c:forEach var="status" items="${orderStatusForm.orderStatusList}"
						varStatus="i">
						<tr class="tr_record">
							<form:hidden path="orderStatusList[${i.index}].id" />
							<td><form:input path="orderStatusList[${i.index}].name"
								size="11" /></td>
							<td><form:input path="orderStatusList[${i.index}].meaning"
								size="11" /></td>
							<td><form:checkbox path="orderStatusList[${i.index}].active" /></td>
							<td><form:checkbox id="selecter" cssClass="checked"
								path="orderStatusList[${i.index}].checked" /></td>
						</tr>
					</c:forEach>
					<tr class="buttonPanel">
						<td colspan="4">
						<input type="submit" class='ui-button ui-state-default ui-corner-all' id="save" name="save" onclick="functionName='save'" value="<spring:message code="admin.orderstatulist.button.save" />"/>

						<input type="submit" class='ui-button ui-state-default ui-corner-all' id="remove" name="remove" onclick="functionName='remove'" value="<spring:message code="admin.orderstatulist.button.remove" />"/>
						</td>
					</tr>
				</tbody>
			</table>


			</td>
		</tr>
	</table>
	<br />
	<table width=70% class="formTable">

		<tr class="formHeader">
			<td colspan="6"><spring:message code="admin.orderstatulist.label.addorderstatus" /></td>
		</tr>

		<tr>
			<td width="42"><spring:message code="admin.orderstatulist.label.name" />:</td>
			<td width="140" align="left"><form:input id="newOrderStatusName"
				path="newOrderStatus.name" size="40" /></td>
		</tr>
		<tr>
			<td width="56"><spring:message code="admin.orderstatulist.label.meaning" />:</td>
			<td width="140" align="left"><form:input
				path="newOrderStatus.meaning" size="40" /></td>
		</tr>
		<tr>
			<td width="42"><spring:message code="admin.orderstatulist.label.active" />:</td>
			<td width="422" align="left"><form:checkbox
				path="newOrderStatus.active" /></td>
		</tr>

		<tr>
			<td colspan="6" class="buttonPanel"><input type="submit" class='ui-button ui-state-default ui-corner-all'
				id="add" name="add" onclick="functionName='add'" value="<spring:message code="admin.orderstatulist.button.save" />" /></td>
		</tr>

	</table>

</form:form><%@include file="/WEB-INF/jsp/include/footer.jsp"%>
</body>
</html>